<template>
  <div>
  <el-breadcrumb separator-class="el-icon-arrow-right">
    <el-breadcrumb-item :to="{ path: '/index' }">首页</el-breadcrumb-item>
    <el-breadcrumb-item>系统中心</el-breadcrumb-item>
    <el-breadcrumb-item>用户管理</el-breadcrumb-item>
  </el-breadcrumb>
    <el-card>
  <el-row>
    <el-form :model="userForm" label-width="70px">
      <el-col :span="5">
        <el-form-item label="姓名">
          <el-input placeholder="姓名/公司名称" v-model="userForm.fullName"></el-input>
        </el-form-item>
      </el-col>
    </el-form>
    <el-button type="info" plain @click="search()">搜索</el-button>
    <el-button type="primary" @click="centerDialogVisible = true">添加用户</el-button>
  </el-row>
  <el-table
    :data="userlist"
    style="width: 100%">
    <el-table-column
      align="center"
      type="index"
      label="编号">
    </el-table-column>
    <el-table-column
      align="center"
      prop="fullName"
      label="姓名/公司名称">
    </el-table-column>
    <el-table-column
      align="center"
      prop="tel"
      label="手机号">
    </el-table-column>
    <el-table-column
      align="center"
      prop="type"
      label="类型">
      <template slot-scope="scope">
        {{scope.row.type|typeFit}}
      </template>
    </el-table-column>
    <el-table-column
      align="center"
      prop="legalPerson"
      label="法人">
    </el-table-column>
    <el-table-column
      align="center"
      prop="balance"
      label="平台余额">
    </el-table-column>
    <el-table-column
      align="center"
      prop="creditScore"
      label="信用分">
    </el-table-column>
    <el-table-column
      align="center"
      prop="status"
      label="状态">
      <template slot-scope="scope">
        {{scope.row.status|statusFit}}
      </template>
    </el-table-column>
    <el-table-column
      align="center"
      prop="regTime"
      label="注册时间">
      <template slot-scope="scope">
        {{scope.row.regTime | datefmt('YYYY-MM-DD HH:mm:ss')}}
      </template>
    </el-table-column>
    <el-table-column
      align="center"
      prop="lastLoginTime"
      label="最近登录">
      <template slot-scope="scope">
        {{scope.row.lastLoginTime | datefmt('YYYY-MM-DD HH:mm:ss')}}
      </template>
    </el-table-column>
    <el-table-column
      align="center"
      prop="source"
      label="来源">
      <template slot-scope="scope">
        {{scope.row.source|sourceFit}}
      </template>
    </el-table-column>
    <el-table-column
      align="center"
      label="操作">
      <!--点击按钮 需要绑定@click的时间 例如 @click="add"-->
      <template slot-scope="scope">
        <el-dropdown split-button type="primary"  size="mini" >
          操作
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item >
              <el-button size="mini" v-if="scope.row.status==0" type="text" @click="IsGoOk(scope.row.id)">
                审核通过
              </el-button>
            </el-dropdown-item>
            <el-dropdown-item style="color: crimson">
              <el-button size="mini" type="text" @click="toBlackName(scope.row.id)" style="color: crimson">
                拉入黑名单
              </el-button>
            </el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </template>
    </el-table-column>
  </el-table>

    <el-dialog title="填写信用分" :visible.sync="ScoredialogFormVisible">
      <el-form :model="AddScore" :rules="AddScoreRule">
        <el-form-item label="信用分" prop="creditScore" >
          <el-input type="number" :min="0"  v-model="AddScore.creditScore" :max="100" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="TijiaoScore()">提交</el-button>
      </div>
    </el-dialog>

    <el-pagination
      align="center"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="page.pagenum"
      :page-sizes="[5, 10, 15, 20]"
      :page-size="page.pagesize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total">
    </el-pagination>
    </el-card>
  </div>
</template>

<script>
    export default {
        name: "borrowuser",
      data(){
        return{
          AddScore:{},
          ScoredialogFormVisible:false,
          page:{
            pagenum:0,
            pagesize:5
          },
          status:'1',
          isShow:false,
          total:0,
          fullName:'',
          userid:'',
          rolelist:[],
          roleIds:{},
          centerDialogVisible:false,
          userDialogVisible:false,
          importExcelVisible:false,
          auth:{token:''},
          userlist:[],
          userForm:{},
          BorrowerId:null,
          AddScoreRule:{
            creditScore:[
              {required: true, message: '请输入分数', trigger: 'blur'},
              {max:100,message:"不可以超过0-100",trigger:"blur"},
              {min:0,message:"不可以超过0-100",trigger:"blur"}
            ]
          }
        }
      },
      methods:{
        TijiaoScore:function(){
          this.$http.post("/finance-service-user/borrower/TijiaoScore/"+this.BorrowerId,this.AddScore).then((res)=>{
            if (res.data.success) {
              this.$message({
                message: res.data.message,
                type: 'success'
              });
              this.ScoredialogFormVisible = false
              this.AddScore = {}
              this.search();
            } else {
              this.$message.error(res.data.message);
            }
            }
          )
        },
        IsGoOk:function(id){
          this.BorrowerId = id
          alert(this.BorrowerId);
          this.$http.post("/finance-service-user/borrower/IsGoOk/"+this.BorrowerId).then((res)=> {
            if (res.data.success) {
              this.$message({
                message: res.data.message,
                type: 'success'
              });
              this.ScoredialogFormVisible = true
            } else {
              this.$message.error(res.data.message);
            }
            }
          )
        },
        LookDetail:function(id){
          this.$http.post("/finance-service-user/borrower/getById/"+id).then((res)=>{

            }
          )
        },
        toBlackName:function(id){
          this.$http.post("/finance-service-user/borrower/toBlackName/"+id).then((res)=>{
            if (res.data.success){
              this.$message({
                message:"拉入成功!",
                type:"success"
              })
              this.search();
            }else {
              this.$message({
                message:"拉入失败!",
                type:"error"
              })
            }
            }
          )
        },
        updateisenable:function(row){
          this.user=row;
          this.user.isEnable=row.isEnable==0?1:0;
          this.$http.post("/user/updateisenable",this.user).then(
            (res)=>{
              if(res.data.success){
                this.$message({
                  message:res.data.message,
                  type: 'success'
                });
              }else{
                this.$message.error(res.data.message);
              }
              this.search();
            }
          );
        },
        addroleuser:function(){
          var formdata=new FormData();
          formdata.append("userid",this.userid);
          formdata.append("roleIds",this.roleIds);
          this.$http.post("/userRole/save",formdata).then(
            (res)=>{
              if(res.data.success){
                this.$message({
                  message: '数据保存成功',
                  type: 'success'
                });
              }else{
                this.$message.error(res.data.message);
              }
              this.userDialogVisible=false;
            }
          );
        },
        userrole: async function (row) {
          this.userDialogVisible = true;
          this.fullName = row.fullName;
          this.userid = row.id;
          let res = await this.$http.get("/role/getrole");
          this.rolelist=res.data.result;
          this.$http.get("/userRole/getroleid/" + row.id).then(
            (res) => {
              if (res.data.success) {
                this.roleIds = res.data.result;
              } else {
                this.$message.error(res.data.message);
              }
            }
          );
        },
        search:function () {
          this.$http.post("/finance-service-user/borrower/getBorrowerList/"+this.page.pagenum+"/"+this.page.pagesize,this.userForm).then(
            (res)=>{
              this.userlist=res.data.result.list;
              this.total=res.data.result.total;
            }
          )
        },
        handleSizeChange:function (val) {
          this.page.pagesize=val;
          this.search();
        },
        handleCurrentChange:function (val) {
          this.page.pagenum=val;
          this.search();
        },
        saveUser:function(){
          this.$http.post("/user/saveuser",this.user).then(
            (res)=>{
              if(res.data.success){
                this.$message({
                  message: '数据保存成功',
                  type: 'success'
                });
              }else{
                this.$message.error('用户名已存在或添加失败');
              }
            }
          );
          this.centerDialogVisible=false;
          this.search();
        },
        crearUser:function () {
          this.user={image:''};
        },
        getuser:function (row) {
          this.user=row;
          this.user.sex=row.sex==0?'0':'1';
          this.centerDialogVisible=true;
        }
      },
      filters:{
        sexfmt:function (val) {
          var str="";
          if(val==0){
            str='男';
          }
          if(val==1){
            str='女';
          }
          return str;
        },
        qifit:function (val) {
          var str="";
          if(val==0){
            str='启用';
          }
          if(val==1){
            str='禁用';
          }
          return str;
        },
        typeFit:function (val) {
          if (val==0){
            return "个人"
          }
          if (val==1){
            return "企业"
          }
        },
        sourceFit:function (val) {
          if (val==0){
            return "个人注册";
          }
          if (val==1){
            return "管理员添加"
          }
        },
        statusFit:function (val) {
          if (val==0){
            return "未审核";
          }
          if (val==1){
            return "已审核通过"
          }
        }
      },
      mounted() {
        this.search();
        this.auth.token=sessionStorage.getItem("token");
      }
    }
</script>

<style scoped>

</style>
